package edu.berkeley.cs160.GroupC;

import edu.berkeley.cs160.GroupC.songs.Song;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class Rating extends WorkoutMusicActivity {

	private TextView artistTextView;
	private TextView songTextView;
	
	private WorkoutMusicApplication app;
	
	private Button backButton;
	private ImageButton lowIntensityButton;
	private ImageButton mediumIntensityButton;
	private ImageButton highIntensityButton;
	
	private Song newSong;

	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.change_rating);
		
		artistTextView = (TextView) findViewById(R.id.ArtistNameTextView2);
		songTextView = (TextView) findViewById(R.id.SongTitleTextView2);
		
		backButton = (Button) findViewById(R.id.backbutton);
        lowIntensityButton=(ImageButton) findViewById(R.id.RateButton1);
        mediumIntensityButton=(ImageButton) findViewById(R.id.RateButton2);
        highIntensityButton=(ImageButton) findViewById(R.id.RateButton3);
        
		app = (WorkoutMusicApplication)getApplication();
		
		setupViews();
		
	}

	private void setupViews() {
		newSong = app.getNewSongAdded();

		String artist = newSong.getArtist();
		String songTitle = newSong.getTitle();
		
		artistTextView.setText(artist);
		songTextView.setText(songTitle);		
		
		// Showing the current rating of the song
		int rating = newSong.getRating();		
		switch (rating) {
		case 1:
			lowIntensityButton.setImageResource(R.drawable.snail4a);
			break;
		case 2:
			mediumIntensityButton.setImageResource(R.drawable.rabbit4a);
			break;
		case 3:
			highIntensityButton.setImageResource(R.drawable.cheetah4a);
			break;
		default:
			break;
		}
		
		
		backButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		lowIntensityButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				newSong.setRating(WorkoutMusicApplication.LOW_INTENSITY);
				Toast temp = Toast.makeText(Rating.this, newSong.getTitle()+"\n will now be played at \nLOW intensity level", Toast.LENGTH_SHORT);
				temp.show();
				finish();
			}
		});
		
		mediumIntensityButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				newSong.setRating(WorkoutMusicApplication.MEDIUM_INTENSITY);
				Toast.makeText(Rating.this, newSong.getTitle()+" \nwill now be played at \nMEDIUM intensity level", Toast.LENGTH_SHORT).show();
				finish();
			}
		});
		
		highIntensityButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				newSong.setRating(WorkoutMusicApplication.HIGH_INTENSITY);
				Toast.makeText(Rating.this, newSong.getTitle()+" \nwill now be played at \nHIGH intensity level", Toast.LENGTH_SHORT).show();
				finish();
			}
		});
	}
	
}
